<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2021-10-14-a</title>
</head>

<body>
    <script>
        //for循环
        for (let i = 0; i <= 9; i++) {
            document.write(i);
            document.write("<br>");
        }
        for (let i = 1; i <= 9; i++) {
            for (let j = 1; j <= i; j++) {
                document.write(j + "*" + i + "=" + i * j);
                document.write("&nbsp;&nbsp");
                if (i * j < 10) {
                    document.write("&nbsp;&nbsp;");

                }
            }
            document.write("<br>");
        }
        var arr = [10, 20, 30, 40];
        var sum = 0;
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        document.write(sum);
        // forEach循环

        var total = 0;
        arr.forEach(element => {
            total += element;
        });
        console.log(total);

        // forin   const声明常量
        for (const key in arr) {
            const element = arr[key];
            total += element;
        }
        console.log(total);
        //while循环
        var total3 = 0;
        var index = 0;
        while (index < arr.length) {
            total3 += arr[index];
            index++;
        }
        console.log(total3);
        // 数组中存放对象
        var news = [{
            "id": 1,
            "title": "新闻标题1"
        }, {
            "id": 2,
            "title": "新闻标题2"
        }, {
            "id": 3,
            "title": "新闻标题3"
        }];
        var html = "<ul>";
        news.forEach(item => {
            html += `<li>${item.title}</li>`;
        });
        html += "</>";
        document.write(html);
    </script>

</body>

</html>